package com.health.viewscontrols.qyinfo;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.health.viewscontrols.NovaApplication;
import com.health.R;
import com.health.adapter.QYAdapter4;
import com.health.fragment.NovaFragment;
import com.health.tablebean.JTYSDoctorContInfoBean;
import com.health.widget.MyListView;

import java.util.List;

/**
 * 签约服务项目包
 * (地方新增服务包)
 * @author nova
 *
 */
public class QY_fwxmb_dfxzFragment extends NovaFragment  {

	private MyListView tongji_list_lv;
	private View baseView;
	QYAdapter4 adapter=null;
	  List<JTYSDoctorContInfoBean> listFWXMs=null;
	@Override
	public View findViews(LayoutInflater inflater) {
		// userInfo = NovaApplication.userInfo;
		baseView = inflater.inflate(R.layout.qyinfo_qyxmb, null);
		findViews(baseView);
// 		setListViewHeightBasedOnChildren(tongji_list_lv);
		addListener();
		setData();
		return baseView;
	}

	public boolean hasServicePackage() {
		if (listFWXMs != null) {
			if (!listFWXMs.isEmpty()) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void setupView(View view) {

	}

	@Override
	public void addListener() {
		 

	}

	public void setData() {
		if(((QYInfo)getActivity()).cont!=null){
			setCheckIDs(((QYInfo)getActivity()).cont.getDetailId());
		}
		
//		List<JTYSCustomerDoctorCont> conts = NovaApplication.fdbmanger.findAllByWhere(JTYSCustomerDoctorCont.class,
//				"cardNum='" + NovaApplication.userInfo.getIDCARD() + "'");
//		if (conts.size() > 0) {
//			
//		}
	}

	public void findViews(View view) {
		tongji_list_lv=(MyListView)view.findViewById(R.id.tongji_list_lv);
//		View head = View.inflate(getActivity(), R.layout.qyinfo_list_head, null);
//		tongji_list_lv.addHeaderView(head);
//		QYAdapter adapter =new QYAdapter(getActivity().getApplicationContext(),QYAdapter.QYINFO_JC);
//		tongji_list_lv.setAdapter(adapter);
		listFWXMs = NovaApplication.fdbmanger.findAllByWhere(JTYSDoctorContInfoBean.class,"officeId='"+NovaApplication.getJgbh()+"' and contractServiceType='DM102-12_3'", "itemType");
		if (listFWXMs.size() > 0) {
			int flagSave = ((QYInfo) getActivity()).getFlagSave();
			adapter =new QYAdapter4(getActivity().getApplicationContext(),listFWXMs,flagSave);
			tongji_list_lv.setAdapter(adapter);
		}
	
	}
	
	public static void setListViewHeightBasedOnChildren(ListView listView) {
	    if(listView == null) return;
	    ListAdapter listAdapter = listView.getAdapter();
	    if (listAdapter == null) {
	        return;
	    }
	    int totalHeight = 0;
	    for (int i = 0; i < listAdapter.getCount(); i++) {
	        View listItem = listAdapter.getView(i, null, listView);
	        listItem.measure(0, 0);
	        totalHeight += listItem.getMeasuredHeight();
	    }
	    ViewGroup.LayoutParams params = listView.getLayoutParams();
	    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	    listView.setLayoutParams(params);

	}
	public   String getCheckIDs(){
		if (adapter != null) {
			return adapter.getCheckedDatas();
		} else {
			return "";

		}
	}
	
	public   void setCheckIDs(String ckids){
		try {
			if (adapter != null) {
				adapter.setCheckedDatas(ckids);
				adapter.notifyDataSetChanged();
			} 
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
